# The rand7() API is already defined for you.
# def rand7():
# @return a random integer in the range 1 to 7

class Solution:
    def rand10(self):
        """
        :rtype: int
        """
        while True:
            i=(rand7()-1)*7+rand7()
            if i<=40:
                return i%10+1
            i=i-40
            i=rand7()+(i-1)*7
            if i<=60:
                return i%10+1
            i=i-60
            i=rand7()+(i-1)*7
            if i<=20:
                return i%10+1